package com.ruoyi.kindergarten.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kindergarten.domain.FoodPurchase;
import com.ruoyi.kindergarten.service.IFoodPurchaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 食材采购记录模块Controller
 * 
 * @author ruoyi
 * @date 2025-10-26
 */
@RestController
@RequestMapping("/kindergarten/foodPurchase")
public class FoodPurchaseController extends BaseController
{
    @Autowired
    private IFoodPurchaseService foodPurchaseService;

    /**
     * 查询食材采购记录模块列表
     */
//    @PreAuthorize("@ss.hasPermi('kindergarten:foodPurchase:list')")
    @GetMapping("/list")
    public TableDataInfo list(FoodPurchase foodPurchase)
    {
        startPage();
        List<FoodPurchase> list = foodPurchaseService.selectFoodPurchaseList(foodPurchase);
        return getDataTable(list);
    }

    /**
     * 导出食材采购记录模块列表
     */
    @PreAuthorize("@ss.hasPermi('kindergarten:foodPurchase:export')")
    @Log(title = "食材采购记录模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FoodPurchase foodPurchase)
    {
        List<FoodPurchase> list = foodPurchaseService.selectFoodPurchaseList(foodPurchase);
        ExcelUtil<FoodPurchase> util = new ExcelUtil<FoodPurchase>(FoodPurchase.class);
        util.exportExcel(response, list, "食材采购记录模块数据");
    }

    /**
     * 获取食材采购记录模块详细信息
     */
//    @PreAuthorize("@ss.hasPermi('kindergarten:foodPurchase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(foodPurchaseService.selectFoodPurchaseById(id));
    }

    /**
     * 新增食材采购记录模块
     */
//    @PreAuthorize("@ss.hasPermi('kindergarten:foodPurchase:add')")
//    @Log(title = "食材采购记录模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FoodPurchase foodPurchase)
    {
        return toAjax(foodPurchaseService.insertFoodPurchase(foodPurchase));
    }

    /**
     * 修改食材采购记录模块
     */
    @PreAuthorize("@ss.hasPermi('kindergarten:foodPurchase:edit')")
    @Log(title = "食材采购记录模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FoodPurchase foodPurchase)
    {
        return toAjax(foodPurchaseService.updateFoodPurchase(foodPurchase));
    }

    /**
     * 删除食材采购记录模块
     */
    @PreAuthorize("@ss.hasPermi('kindergarten:foodPurchase:remove')")
    @Log(title = "食材采购记录模块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(foodPurchaseService.deleteFoodPurchaseByIds(ids));
    }

    /**
     * 统计当天的验收数量
     */
    @GetMapping("/count")
    public List<Integer> count() {
        return  foodPurchaseService.count();
    }
}
